package com.example.demo1;

import com.example.demo1.dto.FruitWeightDto;
import java.math.BigDecimal;
import java.util.Scanner;

public class Test {

    /**
     * 苹果单价
     */
    public static final BigDecimal APPLE_PRICE = BigDecimal.valueOf(8);

    /**
     * 草莓单价
     */
    public static final BigDecimal STRAWBERRY_PRICE = BigDecimal.valueOf(13);

    /**
     * 芒果单价
     */
    public static final BigDecimal MANGO_PRICE = BigDecimal.valueOf(20);

    public static BigDecimal calculateOne(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE);
        return appleAmount.add(strawberryAmount);
    }

    public static BigDecimal calculateTwo(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE);
        BigDecimal mangoAmount = BigDecimal.valueOf(dto.getMangoWeight()).multiply(MANGO_PRICE);
        return appleAmount.add(strawberryAmount).add(mangoAmount);
    }

    public static BigDecimal calculateThree(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE).multiply(BigDecimal.valueOf(0.8));
        BigDecimal mangoAmount = BigDecimal.valueOf(dto.getMangoWeight()).multiply(MANGO_PRICE);
        return appleAmount.add(strawberryAmount).add(mangoAmount);
    }

    public static BigDecimal calculateFour(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE).multiply(BigDecimal.valueOf(0.8));
        BigDecimal mangoAmount = BigDecimal.valueOf(dto.getMangoWeight()).multiply(MANGO_PRICE);
        BigDecimal sumAmount = appleAmount.add(strawberryAmount).add(mangoAmount);
        if (sumAmount.compareTo(BigDecimal.valueOf(100)) >= 0) {
            return sumAmount.subtract(BigDecimal.valueOf(10));
        } else {
            return sumAmount;
        }
    }

    public static void main(String[] args) {
        try {
            FruitWeightDto dto = new FruitWeightDto();
            Scanner a = new Scanner(System.in);
            System.out.println("请输入需要购买的苹果斤数：");
            dto.setAppleWeight(a.nextInt());
            System.out.println("请输入需要购买的草莓斤数：");
            dto.setStrawberryWeight(a.nextInt());
            System.out.println("请输入需要购买的芒果斤数：");
            dto.setMangoWeight(a.nextInt());
            System.out.println("请输入需要执行的程序编号：");
            switch (a.nextInt()) {
                case 1:
                    System.out.println("总金额：" + calculateOne(dto));
                    break;
                case 2:
                    System.out.println("总金额：" + calculateTwo(dto));
                    break;
                case 3:
                    System.out.println("总金额：" + calculateThree(dto));
                    break;
                case 4:
                    System.out.println("总金额：" + calculateFour(dto));
                    break;
            }
        } catch (Exception e) {
            System.out.println("输入的数据格式错误！");
        }
    }
}
